#pragma once
#include "gstring.h"
#include "DirectoryEntry.h"
#include <list>

using namespace std;
/// <summary>
/// Gets a directory listing. Gets both files and folders. Use IsDirectory() to differentiate. Doesn't recurse subdirectories. Use DirectoryTree for that.
/// </summary>
class DirectoryListing
{
public:
	/// <summary>
	/// Constructor
	/// </summary>
	DirectoryListing();
	/// <summary>
	/// Destructor
	/// </summary>
	~DirectoryListing();
	/// <summary>
	/// Reads a directory and stores it in Listing.
	/// </summary>
	/// <param name="directory">Directory to read</param>
	void ReadDirectory(const gstring &directory);
	void Clear();
	/// <summary>
	/// Searches for a file in Listing
	/// </summary>
	/// <param name="file">Returns a reference to the file or NULL if not found.</param>
	/// <returns></returns>
	DirectoryEntry *FindFile(const gstring &file);
	/// <summary>
	/// Pop a directory entry from Listing.
	/// </summary>
	/// <returns>Returns the popped directory entry or NULL.</returns>
	DirectoryEntry* Pop();
	/// <summary>
	/// Combine a file with the folder.
	/// </summary>
	/// <param name="folder">Folder name</param>
	/// <param name="fileName">File name</param>
	/// <param name="output">Where the combined file name will be stored</param>
	static void CombineFileNames(const gstring& folder, const gstring& fileName, gstring& output);
	/// <summary>
	/// Directory listing containing both files and folders.
	/// </summary>
	list<DirectoryEntry*> Listing;
	/// <summary>
	/// Used by FileOperations to add a file to Listing.
	/// </summary>
	/// <param name="name">File name</param>
	/// <param name="size">Size of file in bytes</param>
	/// <param name="time_write">Last modified time. In seconds since the creation of Disco.</param>
	/// <returns></returns>
	DirectoryEntry* AddFile(const gchar* name, INT64 size, INT64 time_write);
};
